
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/17/2011 20:17:43
-- Generated from EDMX file: C:\Users\Amine\Documents\Visual Studio 10\Projects\Movies\MoviesDataBase\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Films];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MovieCastMember_CastMember]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MovieCastMember] DROP CONSTRAINT [FK_MovieCastMember_CastMember];
GO
IF OBJECT_ID(N'[dbo].[FK_MovieCastMember_Movie]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MovieCastMember] DROP CONSTRAINT [FK_MovieCastMember_Movie];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[CastMembers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CastMembers];
GO
IF OBJECT_ID(N'[dbo].[MovieCastMember]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MovieCastMember];
GO
IF OBJECT_ID(N'[dbo].[Movies]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Movies];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'CastMembers'
CREATE TABLE [dbo].[CastMembers] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Person] nvarchar(4000)  NULL,
    [Activity] nvarchar(4000)  NULL,
    [Role] nvarchar(4000)  NULL,
    [Picture] nvarchar(4000)  NULL
);
GO

-- Creating table 'Movies'
CREATE TABLE [dbo].[Movies] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Nationalite] nvarchar(4000)  NULL,
    [Genre] nvarchar(4000)  NULL,
    [DateSortie] nvarchar(4000)  NULL,
    [Synopsis] nvarchar(4000)  NULL,
    [MovieCertificate] nvarchar(4000)  NULL,
    [Trailer] nvarchar(4000)  NULL,
    [Title] nvarchar(4000)  NULL,
    [IsDownloading] bit  NULL,
    [Poster] nvarchar(4000)  NULL,
    [AllocineUrl] nvarchar(4000)  NULL,
    [Path] nvarchar(4000)  NULL
);
GO

-- Creating table 'MovieCastMember'
CREATE TABLE [dbo].[MovieCastMember] (
    [CastMembers_ID] int  NOT NULL,
    [Movies_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'CastMembers'
ALTER TABLE [dbo].[CastMembers]
ADD CONSTRAINT [PK_CastMembers]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Movies'
ALTER TABLE [dbo].[Movies]
ADD CONSTRAINT [PK_Movies]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [CastMembers_ID], [Movies_ID] in table 'MovieCastMember'
ALTER TABLE [dbo].[MovieCastMember]
ADD CONSTRAINT [PK_MovieCastMember]
    PRIMARY KEY NONCLUSTERED ([CastMembers_ID], [Movies_ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CastMembers_ID] in table 'MovieCastMember'
ALTER TABLE [dbo].[MovieCastMember]
ADD CONSTRAINT [FK_MovieCastMember_CastMember]
    FOREIGN KEY ([CastMembers_ID])
    REFERENCES [dbo].[CastMembers]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Movies_ID] in table 'MovieCastMember'
ALTER TABLE [dbo].[MovieCastMember]
ADD CONSTRAINT [FK_MovieCastMember_Movie]
    FOREIGN KEY ([Movies_ID])
    REFERENCES [dbo].[Movies]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MovieCastMember_Movie'
CREATE INDEX [IX_FK_MovieCastMember_Movie]
ON [dbo].[MovieCastMember]
    ([Movies_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------